from nodetypes.formats.mml.Events import EventHandler
from nodetypes.core.Preferences import UrlGuestPreferencesUpdater

from myelin.server.lib.http import Status

from forms import Reset
 
from base import EventHandler

class EventHandler(EventHandler):
           
    newPreferencesUpdater   = UrlGuestPreferencesUpdater
    
    newResetForm            = Reset.Form
                
    def process(self, context, source):
        if context.account.isLoggedIn():
            return self.redirectToUserPreferences(context)
        
        eventData = context.event.data
        
        eventData.form = self.newResetForm()
        
        eventData.status = u'success'
        eventData.status_type = u'reset-success'
        
        eventData.stage = 0
        eventData.submits = context.transform.submitEvents[0]
        
        context.model = context.nodeType.retrieveModel(context)
        
        return self.newDocument().createDocument(context, source)